# -*- Tcl -*-
# Commands covered:  cep
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2000 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: tclsample.test,v 1.1 2002/03/06 05:35:31 hobbs Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

package require ceptcl

testConstraint cep 0


test cep-1.1 {arg parsing for cep command} {cep} {
    list [catch {cep -server} msg] $msg
} {1 {no argument given for -server option}}
test cep-1.2 {arg parsing for cep command} {cep} {
    list [catch {cep -server foo} msg] $msg
} {1 {wrong # args: should be either:
cep ?-local? ?-datagram? ?-async? name
cep ?-local? ?-datagram? -server command name}}
test cep-1.3 {arg parsing for cep command} {acep} {
    list [catch {cep -myaddr} msg] $msg
} {1 {no argument given for -myaddr option}}
test cep-1.4 {arg parsing for cep command} {acep} {
    list [catch {cep -myaddr 127.0.0.1} msg] $msg
} {1 {wrong # args: should be either:
cep ?-myaddr addr? ?-myport myport? ?-async? host port
cep -server command ?-myaddr addr? port}}
test cep-1.5 {arg parsing for cep command} {acep} {
    list [catch {cep -myport} msg] $msg
} {1 {no argument given for -myport option}}
test cep-1.6 {arg parsing for cep command} {acep} {
    list [catch {cep -myport xxxx} msg] $msg
} {1 {expected integer but got "xxxx"}}
test cep-1.7 {arg parsing for cep command} {acep} {
    list [catch {cep -myport 2522} msg] $msg
} {1 {wrong # args: should be either:
cep ?-myaddr addr? ?-myport myport? ?-async? host port
cep -server command ?-myaddr addr? port}}
test cep-1.8 {arg parsing for cep command} {cep} {
    list [catch {cep -froboz} msg] $msg
} {1 {bad option "-froboz": must be -async, -server, -local, or -datagram}}
test cep-1.9 {arg parsing for cep command} {acep} {
    list [catch {cep -server foo -myport 2521 3333} msg] $msg
} {1 {Option -myport is not valid for servers}}
test cep-1.10 {arg parsing for cep command} {acep} {
    list [catch {cep host 2528 -junk} msg] $msg
} {1 {wrong # args: should be either:
cep ?-myaddr addr? ?-myport myport? ?-async? host port
cep -server command ?-myaddr addr? port}}
test cep-1.11 {arg parsing for cep command} {acep} {
    list [catch {cep -server callback 2520 --} msg] $msg
} {1 {wrong # args: should be either:
cep ?-myaddr addr? ?-myport myport? ?-async? host port
cep -server command ?-myaddr addr? port}}
test cep-1.12 {arg parsing for cep command} {acep} {
    list [catch {cep foo badport} msg] $msg
} {1 {expected integer but got "badport"}}
test cep-1.13 {arg parsing for socket command} {cep} {
    list [catch {socket -async -server} msg] $msg
} {1 {cannot set -async option for server sockets}}
test cep-1.14 {arg parsing for socket command} {cep} {
    list [catch {socket -server foo -async} msg] $msg
} {1 {cannot set -async option for server sockets}}


test tclcep-1.1 {incorrect command usage} {cep} {
    list [catch {cep} errMsg] $errMsg
} {1 {wrong # args: should be either:
cep ?-local? ?-datagram? ?-async? name
cep ?-local? ?-datagram? -server command name}}

test tclcep-1.2 {incorrect usage of -async option} {acep} {
    list [catch {cep -async "string"} errMsg] $errMsg
} {1 {invalid log2base: -log2base must be integer in range 1...6}}



# cleanup
::tcltest::cleanupTests
return
